package tmall.secondkill.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tmall.framework.Response;
import tmall.secondkill.common.ErrorCodeEnum;
import tmall.secondkill.entity.Commodity;
import tmall.secondkill.mapper.CommodityMapper;
import tmall.secondkill.service.CommodityService;

import java.util.List;

@Service
public class CommodityServiceImpl implements CommodityService {

    @Autowired
    private CommodityMapper commodityMapper;

    @Override
    public Response addCommodity(Commodity input) {
        commodityMapper.insert(input);
        return Response.of(ErrorCodeEnum.SUCCESS);
    }

    @Override
    public Response getAllCommodity() {
        List<Commodity> commodities = commodityMapper.selectList(null);
        return Response.of(ErrorCodeEnum.SUCCESS, commodities);
    }

    @Override
    public Response deleteCommodity(long id) {
        commodityMapper.deleteById(id);
        return Response.of(ErrorCodeEnum.SUCCESS);
    }

    @Override
    public Response updateCommodityById(Commodity input) {
        commodityMapper.updateById(input);
        return Response.of(ErrorCodeEnum.SUCCESS);
    }
}
